package com.jinzhi.jinzhidata.util;

import com.github.qcloudsms.SmsSingleSender;
import com.github.qcloudsms.SmsSingleSenderResult;
import lombok.extern.slf4j.Slf4j;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @description
 * @date 2019-08-28 15:41
 **/
public class SMSSendUtil {

    public static String sendSMS(String phoneNumber, Integer templateId, String[] params) {
        SmsSingleSender sender = new SmsSingleSender(Constant.SMS_SDK_APPID, Constant.SMS_APPKEY);
        // 签名参数未提供或者为空时会使用默认签名发送短信
        SmsSingleSenderResult result = null;
        try {
            result = sender.sendWithParam("86", phoneNumber, templateId, params, Constant.SMS_SIGN, "", "");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result.errMsg;
    }

    public static void main(String[] args) {
//        sendSMS("15957911326",new String[]{"浙G69634","范碧成","1","15:46"});
//        List<CustomerLoyalty> list = new ArrayList<>();
//        CustomerLoyalty customerLoyalty1 = new CustomerLoyalty();
//        CustomerLoyalty customerLoyalty2 = new CustomerLoyalty();
//        PrimaryKey primaryKey1 = new PrimaryKey();
//        PrimaryKey primaryKey2 = new PrimaryKey();
//        customerLoyalty1.setPrimaryKey(primaryKey1);
//        customerLoyalty2.setPrimaryKey(primaryKey2);
//        primaryKey1.setCarNO("123");
//        primaryKey2.setCarNO("123");
//        list.add(customerLoyalty1);
//        System.out.println(list.contains(customerLoyalty2));
//        System.out.println(null+"");
        SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");//设置日期格式
        String nowTime = dateFormat.format(new Date());// new Date()为获取当前系统时间
        String[] messageData = new String[]{"王敏忠", "浙G25A32", "阳光绿洲湾小区", nowTime};
        sendSMS("15957911326", Constant.SMS_TEMPLATE_ID, messageData);
    }
}
